/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   gbx-emu - debuggerwidget.h                                            *
 *   gbx-emu homepage: http://code.google.com/p/gbx-emu/                   *
 *   Copyright (C) 2009 olejl77@gmail.com                                  *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef __DEBUGGERWIDGET_H__
#define __DEBUGGERWIDGET_H__

#include <QtGui/QWidget>
#include <QSignalMapper>
#include "../core/common.h"

namespace Ui
{
    class DebuggerWidgetClass;
}
class DisasmModel;
class RegisterModel;
class Debugger;
class MainWindow;
class Gameboy;
class Cpu;
class Memory;
class DebuggerWidget : public QWidget
{
friend class BreakpointsWidget;
    Q_OBJECT
public:
    DebuggerWidget(MainWindow *m, QWidget *parent = 0);
    ~DebuggerWidget();
    void updateBP(unsigned short addr);
    void setGameboy(Gameboy *ptr) { _gb = ptr; }
    void setMemory(Memory *ptr) { _mem = ptr; }
    void setCpu(Cpu *ptr) { _cpu = ptr; }
    void setDebugger(Debugger *ptr) { _dbg = ptr; }
    void initDebugger();
    void updatePC(unsigned short pc);

protected:
    void closeEvent(QCloseEvent* event);

signals:
    void debuggerStep();

private slots:
    void clicked(const QString text);

private:
    Gameboy *_gb;
    Cpu *_cpu;
    Memory *_mem;
    Debugger *_dbg;

    Ui::DebuggerWidgetClass *ui;
    Debugger *debugger;
    MainWindow *main;

    QSignalMapper *smDebugger;

    DisasmModel *modelDisasm;
    RegisterModel *modelRegs;
    RegisterModel *modelFlags;
    RegisterModel *modelIO;
    RegisterModel *modelOAM;

    QStringList oplist;
    QStringList oplist_cb;
    QStringList pcs;
    QStringList opcodes;
    QStringList args;
    QStringList mnemonicRegs;
    QStringList mnemonicFlags;
    QStringList mnemonicIO;
    QStringList mnemonicOAM;

    u8 A;
    u16 BC, DE, HL, SP;
    u8 IME, Z_flag, N_flag, H_flag, C_flag;
    u8 *io;
    u8 *oam;

    QColor color_DEFAULT;
    QColor color_CHANGED;
    QColor color_PC;
    QColor color_BP;

    enum { rowHeight = 12 };

    const u8 *cpuA;
    const u16 *cpuBC;
    const u16 *cpuDE;
    const u16 *cpuHL;
    const u16 *cpuSP;
    const u8 *cpuIME;
    const u8 *cpuZ;
    const u8 *cpuN;
    const u8 *cpuH;
    const u8 *cpuC;
    const u8 *memory;
};

#endif // __DEBUGGERWIDGET_H__

